/* 
  添加等级
  author:zsy
  date: 2024-1-18
*/
<template>
  <div>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="等级名称" prop="levelname">
        <el-input v-model="ruleForm.levelname"></el-input>
      </el-form-item>
  
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>


<script>
import { addLevel } from "@/api/level";

export default {
  data() {
      return {
        ruleForm: {
          levelname: '',
        },
        rules: {
          levelname: [
            { required: true, message: '请输入等级名称', trigger: 'blur' },
          
          ],
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            addLevel({
              levelname:this.ruleForm.levelname,
            }).then((res)=>{
              this.$message({
                message:"success",
                type:"success",
              });
              this.$refs[formName].resetFields();
              this.$route.push('/level/levelList')
            }).catch((err)=>{
              console.log(err)
            });
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    },
    // created(){
    //   this.submitForm(ruleForm.levelname)
    //   this.resetForm()
    // }
}
</script>

<style>

</style>
